<?php
/*
	include ('../config/conexao.php');

	include ('../config/validacao.php');
	if(isset($_POST["id"]) ){

		$sql = "DELETE FROM secretaria WHERE idsecretaria='".$_POST['id']."';";
		mysql_query("SET NAMES 'utf8'");
		$retval = mysql_query($sql,$link );
		if(! $retval )
		{
			die('Erro ao excluir registro: ' . mysql_error());
			//echo $sql;
		}
		else{
			echo "Registro excluido!";
		}
	}
*/

	include ('../config/conexao.php');
	include ('../config/validacao.php');
	include ('../modlogin/logger.php');

	if(isset($_GET["id"]) ){
		$rs = mysql_query('SELECT idsetor FROM `setor` WHERE `secretaria_idsecretaria` ='.$_GET["id"]);
		$string = '';
		// loop through each zipcode returned and format the response for jQuery
		if ( $rs && mysql_num_rows($rs) )
		{
				while( $row = mysql_fetch_array($rs) )
				{
						$string = $string.$row['idsetor']."|";

				}
				echo "<script type='text/javascript' language='Javascript'>
				var resposta = confirm('Existem setores cadastrados neste local. Deseja Altera-los de local?');
				if (resposta == true) {
						window.location.href = '/grambel/c_setor/editar_setor.php?string=".$string."';
				}else{
						alert('Local nao excluido!')
						window.location.href = 'e_secretaria.php';
				}
				</script>";

		}else{
				$sql = "DELETE FROM secretaria WHERE idsecretaria='".$_GET['id']."';";
				mysql_query("SET NAMES 'utf8'");
				$retval = mysql_query($sql,$link );
				if(!$retval )
				{
						Logger('Erro ao excluir local:'.mysql_error());
						echo "<script>alert('Erro ao excluir local: ". mysql_error()."');</script>";
						//echo $sql;
						echo "<script>window.location.href = 'e_secretaria.php'";
				}
				else{
						Logger($sql,99);
						echo "<script>alert('Local excluido!');</script>";
						echo "<script>window.location.href = 'e_secretaria.php';</script>";
				}
		}
	}


?>
